package fr.umlv.m2.jee.spij.persistence.education;

import fr.umlv.m2.jee.spij.persistence.actor.StudentFieldWork;
import fr.umlv.m2.jee.spij.persistence.actor.TeacherFieldWork;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Entity FieldWork who contain information about fieldWork.
 *
 * @author Lounes Akroune
 * @author Aurelien Scelles
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "FIE_FIELDWORK")
public class FieldWork extends Practice {

    /**
     * Primary key.
     */
    @Id
    @Column(name = "FIE_ID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    /**
     * Closing date for submission. Put at null if no record is excepted.
     *
     * @see org.joda.time.contrib.hibernate.PersistentDateTime
     */
    @Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
    @Column(name = "FIE_DEADLINE")
    private DateTime deadLine;

    /**
     * Id of the linked unit.
     */
    @Column(name = "FIE_UNI_ID")
    private Long unit;

    /**
     * List of students.
     */
    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "SF_FIELDWORK_ID", referencedColumnName = "FIE_ID")
    private List<StudentFieldWork> students = new ArrayList<StudentFieldWork>();

    /**
     * List of teachers.
     */
    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "TF_FIELDWORK_ID", referencedColumnName = "FIE_ID")
    private List<TeacherFieldWork> teachers = new ArrayList<TeacherFieldWork>();


    /**
     * Setter of Id.
     *
     * @param newId the new id to set.
     */
    public final void setId(final long newId) {
        this.id = newId;
    }

    /**
     * Getter of Id.
     *
     * @return primary key
     */
    public final long getId() {
        return id;
    }

    /**
     * Setter of deadLine.
     *
     * @param newDeadLine the new dead line to set.
     */
    public final void setDeadLine(final DateTime newDeadLine) {
        this.deadLine = newDeadLine;
    }

    /**
     * Getter of deadLine.
     *
     * @return closing date
     */
    public final DateTime getDeadLine() {
        return deadLine;
    }

    /**
     * Setter of linked Unit.
     *
     * @param newUnit the new unit id to set.
     */
    public final void setUnit(final Long newUnit) {
        this.unit = newUnit;
    }

    /**
     * Getter of linked Unit.
     *
     * @return unit id.
     */
    public final Long getUnit() {
        return unit;
    }

    /**
     * @param studentList a list of student to set.
     */
    public final void setStudents(final List<StudentFieldWork> studentList) {
        this.students = studentList;
    }

    /**
     * @return a list of studentFieldWork.
     */
    public final List<StudentFieldWork> getStudents() {
        return students;
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#add(java.lang.Object)
     */
    public boolean addStudent(StudentFieldWork arg0) {
        return students.add(arg0);
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#get(int)
     */
    public StudentFieldWork getStudent(int arg0) {
        return students.get(arg0);
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#remove(java.lang.Object)
     */
    public boolean removeStudent(Object arg0) {
        return students.remove(arg0);
    }

    /**
     * @return
     *
     * @see java.util.List#size()
     */
    public int numberOfStudents() {
        return students.size();
    }

    public void setTeachers(List<TeacherFieldWork> teachers) {
        this.teachers = teachers;
    }

    public List<TeacherFieldWork> getTeachers() {
        return teachers;
    }

    /**
     * @param e
     *
     * @return
     *
     * @see java.util.List#add(java.lang.Object)
     */
    public boolean addTeacher(TeacherFieldWork e) {
        return teachers.add(e);
    }

    /**
     * @param index
     *
     * @return
     *
     * @see java.util.List#get(int)
     */
    public TeacherFieldWork getTeacher(int index) {
        return teachers.get(index);
    }

    /**
     * @param o
     *
     * @return
     *
     * @see java.util.List#remove(java.lang.Object)
     */
    public boolean removeTeacher(Object o) {
        return teachers.remove(o);
    }

    /**
     * @return
     *
     * @see java.util.List#size()
     */
    public int numberOfTeachers() {
        return teachers.size();
    }

}
